﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;

namespace QuartzNet
{
    class Program
    {
        static async Task Main(string[] args)
        {
            try
            {
                // 从工厂中获取调度程序实例
                var props = new NameValueCollection
                {
                    { "quartz.serializer.type", "binary" }
                };
                var factory = new StdSchedulerFactory(props);
                var scheduler = await factory.GetScheduler();
                // 开启调度器
                await scheduler.Start();
                var job = JobBuilder.Create<TotalJob>()
                       .WithIdentity("job1", "group1")
                       .Build();
                // 触发作业立即运行，然后每10秒重复一次，无限循环
                var trigger = TriggerBuilder.Create()
                    .WithIdentity("totalJob", "group1")
                    .StartNow()
                    .WithSimpleSchedule(x => x
                        .WithIntervalInSeconds(3)
                        .RepeatForever())
                    .Build();
                // 告诉Quartz使用我们的触发器来安排作业
                await scheduler.ScheduleJob(job, trigger);

                // 等待60秒
                // await Task.Delay(TimeSpan.FromSeconds(5));

                Console.ReadKey();
                // 关闭调度程序
                await scheduler.Shutdown();
            }
            catch (Exception ex)
            {

                await Console.Out.WriteLineAsync(ex.Message);
            }
        }
    }
}
